from jili.calc import calcor_base
from scipy.stats import siegelslopes
import numpy as np

# 计算ICU均线

class EMA(calcor_base):
    def __init__(self,ta_arg={}):
        self.out = ["ema_ma"]
        self.input = ["close"]
        self.parameters = {"timeperiod":10,"matype":1}
        super().__init__(ta_arg)
        self.batch=self.parameters["timeperiod"]
        self.isfirst=True
        self.prerst=None
        self.factor=2/(self.batch+1)
        self.factor0=1-self.factor
    def calc(self):
        srs= self.hisbars[self.input[0]]
        if self.prerst   is not None:
            f=self.factor*srs[-1]+self.factor0*self.prerst
        else:
            f=srs[0]
            for i in srs[1:]:
                f=self.factor*i+self.factor0*f
        self.prerst=f
        return f
